import maya.cmds as mc

# this script can create Drvin joint with the space pointctrl.

def copyJnt():
        mc.select('*_Drv')
        mc.delete(cn=1)
        mc.parent(w=1)
        mc.makeIdentity(apply=True,t=0,r=1,s=0,n=0)

def connectJnt(*jnt):
        num = len(jnt)
        for i in range( 0,(num-1) ):
                mc.select(jnt[i+1],r=1)
                mc.select(jnt[i],tgl=1)
                mc.parent()
        mc.select(cl=1)

def createJnt(component):
        if component == 'all':
                #arm
                connectJnt( 'Left_arm01_Drv' , 'Left_arm02_Drv' , 'Left_arm03_Drv')
                #finger
                connectJnt('Left_Thumb01_Drv' , 'Left_Thumb02_Drv' , 'Left_Thumb03_Drv' , 'Left_Thumb04_Drv')
                connectJnt('Left_Index01_Drv' , 'Left_Index02_Drv' , 'Left_Index03_Drv' , 'Left_Index04_Drv')
                connectJnt('Left_Middle01_Drv' , 'Left_Middle02_Drv' , 'Left_Middle03_Drv' , 'Left_Middle04_Drv')
                connectJnt('Left_Ring01_Drv' , 'Left_Ring02_Drv' , 'Left_Ring03_Drv' , 'Left_Ring04_Drv')
                connectJnt('Left_Pinky01_Drv' , 'Left_Pinky02_Drv' , 'Left_Pinky03_Drv' , 'Left_Pinky04_Drv')

                fingerGlList = ['Left_Thumb01_Drv'  , 'Left_Index01_Drv' , 'Left_Middle01_Drv' , 'Left_Ring01_Drv' , 'Left_Pinky01_Drv']
                for x in fingerGlList:
                        connectJnt('Left_hand_Drv' , x)

                # leg and foot
                connectJnt('Left_leg01_Drv' , 'Left_leg02_Drv' , 'Left_leg03_Drv ' )
                connectJnt('Left_foot01_Drv' , 'Left_foot02_Drv' , 'Left_foot03_Drv ' )

                #torso and neck
                connectJnt('Torso1_Drv' , 'Torso2_Drv' , 'Torso3_Drv' , 'Torso4_Drv' , 'Chest_Drv')
                connectJnt('Neck_Drv' , 'Head_Drv' , 'HeadToe_Drv' )

        elif component == 'arm':
                connectJnt( 'Left_arm01_Drv' , 'Left_arm02_Drv' , 'Left_arm03_Drv')

        elif component == 'leg':
                connectJnt('Left_leg01_Drv' , 'Left_leg02_Drv' , 'Left_leg03_Drv ' )

        elif component == 'hand':
                connectJnt('Left_Thumb01_Drv' , 'Left_Thumb02_Drv' , 'Left_Thumb03_Drv' , 'Left_Thumb04_Drv')
                connectJnt('Left_Index01_Drv' , 'Left_Index02_Drv' , 'Left_Index03_Drv' , 'Left_Index04_Drv')
                connectJnt('Left_Middle01_Drv' , 'Left_Middle02_Drv' , 'Left_Middle03_Drv' , 'Left_Middle04_Drv')
                connectJnt('Left_Ring01_Drv' , 'Left_Ring02_Drv' , 'Left_Ring03_Drv' , 'Left_Ring04_Drv')
                connectJnt('Left_Pinky01_Drv' , 'Left_Pinky02_Drv' , 'Left_Pinky03_Drv' , 'Left_Pinky04_Drv')
                fingerGlList = ['Left_Thumb01_Drv'  , 'Left_Index01_Drv' , 'Left_Middle01_Drv' , 'Left_Ring01_Drv' , 'Left_Pinky01_Drv']
                for x in fingerGlList:
                        connectJnt('Left_hand_Drv' , x)

        elif component == 'foot':
                connectJnt('Left_foot01_Drv' , 'Left_foot02_Drv' , 'Left_foot03_Drv ' )
                #mc.setAttr('foot_Space_Ctr.visibility' , 0)

        elif component == 'spline':
                connectJnt('Torso1_Drv' , 'Torso2_Drv' , 'Torso3_Drv' , 'Torso4_Drv' , 'Chest_Drv')

        elif component == 'threeSpanLeg':
                connectJnt('Left_Leg01_Drv','Left_Leg02_Drv','Left_Leg03_Drv','Left_Leg04_Drv',)
                connectJnt('Left_foot01_Drv' , 'Left_foot02_Drv' , 'Left_foot03_Drv ' )
                #mc.setAttr('foot_Space_Ctr.visibility' , 0)
                #
                #mc.parent('Left_legUp_pole_Drv' , 'Left_Leg02_Drv')

def finalCreateJnt(cpt,mirror):
        copyJnt()
        createJnt(cpt)
        if mirror == 'on':
                if  cpt == 'all':
                        mc.mirrorJoint('Left_arm01_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_leg01_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_hand_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_foot01_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )

                        mc.mirrorJoint('Left_Inside_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_Outside_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_Heel_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_shoudler_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_elbow_Pole_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_knee_Pole_Drv' , mirrorYZ=True , mirrorBehavior=False , searchReplace=('Left_', 'Right_') )

                elif  cpt == 'arm':
                        mc.mirrorJoint('Left_arm01_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_elbow_Pole_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )

                elif  cpt == 'leg':
                        mc.mirrorJoint('Left_leg01_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_knee_Pole_Drv' , mirrorYZ=True , mirrorBehavior=False , searchReplace=('Left_', 'Right_') )

                elif  cpt == 'hand':
                        mc.mirrorJoint('Left_hand_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )

                elif  cpt == 'foot':
                        mc.mirrorJoint('Left_foot01_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )

                        mc.mirrorJoint('Left_Outside_Drv' , mirrorYZ=True , mirrorBehavior=False , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_Inside_Drv' , mirrorYZ=True , mirrorBehavior=False , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_Heel_Drv' , mirrorYZ=True , mirrorBehavior=False , searchReplace=('Left_', 'Right_') )

                elif  cpt == 'threeSpanLeg':
                        mc.mirrorJoint('Left_Leg01_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_leg_global_pole_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint( 'Left_legUp_pole_Drv' , mirrorYZ=True , mirrorBehavior=False , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_foot01_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )

                        mc.mirrorJoint('Left_Outside_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_Inside_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )
                        mc.mirrorJoint('Left_Heel_Drv' , mirrorYZ=True , mirrorBehavior=True , searchReplace=('Left_', 'Right_') )

        elif mirror == 'off':
                pass



